<template>
  <div class="flexContent">
    <div class="searchBox">

      <el-form class="demo-form-inline" label-position="left" label-width="auto">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="暂无搜索">
                  <el-input v-clearEmoji v-model.trim="sForm.number" clearable style="width: 95%" placeholder="" />
                </el-form-item>
              </el-col>
              <!-- <el-col :span="8">
                <el-form-item label="仓库">
                  <el-select v-model="sForm.warehouseId" clearable style="width: 70%" popper-class="eloption"
                    placeholder="请选择仓库" filterable @click.native="reqWarehouseList">
                    <el-option v-for="item in warehouseList" :key="item.id" :value="item.id" :label="item.name" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入库日期">
                  <el-date-picker v-model="date" clearable style="width: 70%" type="daterange" unlink-panels
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col> -->
            </el-row>
            <!-- <el-row :gutter="24">
              <el-col :span="8">
                <el-form-item label="供应商">
                  <el-select v-model="sForm.supplierId" clearable style="width: 70%" popper-class="eloption"
                    placeholder="请选择供应商" filterable @click.native="getSCMList">
                    <el-option v-for="item in supplierList" :key="item.id" :value="item.id" :label="item.name" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item v-if="isAdmin" label="入库员">
                  <el-select v-model="sForm.userId" clearable style="width: 70%" popper-class="eloption"
                    placeholder="请选择入库员" filterable @click.native="reqBuyerList">
                    <el-option v-for="item in userList" :key="item.id" :value="item.id" :label="item.employeeName" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row> -->
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchFn" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="resetFn" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="add">
      <el-button class="addBtn" v-has="'returnTOwarehouse_add'" @click="addFn">新增</el-button>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" align="center" style="width: 100%"
          height="100%" size="medium">
          <vxe-column type="seq" width="80" title="序号" />
          <vxe-column field="returnsNumber" title="退货单号"
            :min-width="elTableAdaptationWidth('returnsNumber', orderList)" />
          <vxe-column field="commodityName" title="商品名称"
            :min-width="elTableAdaptationWidth('commodityName', orderList)" />
          <vxe-column field="bigPacking" title="大包装" min-width="120" />
          <vxe-column field="batchNumber" title="批次号" :min-width="elTableAdaptationWidth('batchNumber', orderList) + 10" />
          <vxe-column field="manufactureTime" title="生产日期" min-width="120">
            <template v-slot="{ row }">
              <span>{{ row.manufactureTime | parseTime('YYYY-MM-DD') }}</span>
            </template>
          </vxe-column>
          <vxe-column field="warehouseName" title="仓库名称"
            :min-width="elTableAdaptationWidth('warehouseName', orderList)" />
          <vxe-column field="regionName" title="区域名称" :min-width="elTableAdaptationWidth('regionName', orderList)" />
          <vxe-column field="positionName" title="仓位名称" :min-width="elTableAdaptationWidth('positionName', orderList)" />
          <vxe-column field="inboundCount" title="入库数量" min-width="120" />
          <vxe-column field="username" title="入库员" :min-width="elTableAdaptationWidth('username', orderList)" />
          <vxe-column field="inboundTime" title="入库日期" min-width="150">
            <template v-slot="{ row }">
              <span>{{ row.inboundTime | parseTime }}</span>
            </template>
          </vxe-column>

          <!-- <vxe-column v-if="$showFn(['warehouseentry_detail'])" title="操作" fixed="right" width="100">
            <template v-slot="{ row }">
              <el-button type="text" style="margin-right: 10px" @click.stop="entryDetail(row)">详情</el-button>
            </template>
          </vxe-column> -->
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination :current-page="page.pageNum" background :page-sizes="$pageSizes" :page-size="page.pageSize"
          layout="total,->, sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import { getSCMList } from "@/api/scm";
import { reqBuyerList } from "@/api/procure";
import { isAdmin } from "@/api/user";
import { getReturnWareSelectist, reqWarehouseList } from "@/api/warehouse";
export default {
  name: "WarehouseEntry",
  data() {
    return {
      name: "",
      sForm: {
        supplierId: "",
        userId: "",
        warehouseId: "",
        number: "",
        maxDate: "",
        minDate: "",
      },
      isSearch: false,
      date: [],
      supplierList: [],
      warehouseList: [],
      userList: {},
      orderList: [],
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
      isAdmin: false,
    };
  },
  created() {
    // this.getSCMList();
    // this.reqBuyerList();
    // this.reqWarehouseList();
    this.getReturnWareSelectist();
    this.getIsAdmin();
  },
  methods: {
    async getSCMList() {
      const res = await getSCMList();
      if (res.code === 200) {
        this.supplierList = res.data.list;
        console.log(this.supplierList, "supplierList");
      }
    },
    async getIsAdmin() {
      const res = await isAdmin();
      if (res.code === 200) {
        console.log(res, "成功");
        this.isAdmin = res.data;
      }
      console.log(res);
    },
    async reqBuyerList() {
      const res = await reqBuyerList({ code: "3" });
      if (res.code === 200) {
        const data = res.data;
        this.userList = data;
        console.log(res.data);
      }
    },
    async reqWarehouseList() {
      const res = await reqWarehouseList();
      if (res.code === 200) {
        this.warehouseList = res.data;
        console.log(this.warehouseList, "Ware");
      }
    },
    async getReturnWareSelectist() {
      if (!this.isSearch) {
        this.sForm = {
          supplierId: "",
          userId: "",
          warehouseId: "",
          number: "",
          maxDate: "",
          minDate: "",
        };
      }
      const res = await getReturnWareSelectist({ ...this.page, ...this.sForm });
      if (res.code === 200) {
        console.log(res.data, "list");
        this.orderList = res.data.list;
        this.page.total = res.data.total;
        this.page.pageSize = res.data.pageSize;
        this.page.pageNum = res.data.pageNum;
        const $table = this.$refs.xTable1
        $table.loadData(this.orderList);
      }
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageNum = 1;
      console.log(`每页 ${val} 条`);
      this.getReturnWareSelectist();
    },
    // 获取页数改变
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.getReturnWareSelectist();
    },
    addFn() {
      this.$router.push("returnTOwarehouseAdd");
    },
    async searchFn() {
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };

      this.isSearch = true;
      this.sForm.maxDate = this.date?.length ? this.date[1] : "";
      this.sForm.minDate = this.date?.length ? this.date[0] : "";
      this.getReturnWareSelectist();
    },
    resetFn() {
      this.sForm = {
        supplierId: "",
        userId: "",
        warehouseId: "",
        number: "",
        maxDate: "",
        minDate: "",
      };
      this.isSearch = false;
      this.date = [];
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };
      this.getReturnWareSelectist();
    },
    entryDetail(row) {
      this.$router.push({
        path: "warehouseEntryDetail",
        query: {
          id: row.id,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
